package cn.tyf.service.imp;

import cn.tyf.dao.WxFunDao;
import cn.tyf.domain.PageBean;
import cn.tyf.domain.User;
import cn.tyf.domain.WxFun;
import cn.tyf.service.WxFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 小程序功能
 */
@Service
public class WxFunServiceImpl implements WxFunService {

    @Autowired
    private WxFunDao wxFunDao;
    @Autowired
    private PageBean pageBean;
    @Override
    public List<WxFun> wxFunList(){
        return wxFunDao.wxFunList();
    }

    @Override
    public void addFun(WxFun wxFun) {
        wxFunDao.addFun(wxFun);
    }

    @Override
    public PageBean findWxFunPage(Integer currentPage, Integer pageSize) {
        //1总记录数
        Integer count = wxFunDao.count();
        pageBean.setTotalCount(count);
        //总页数
        Integer totalPage = (count % pageSize==0) ? count / pageSize : count / pageSize +1;
        pageBean.setTotalPage(totalPage);
        //当前页码
        pageBean.setCurrentPage(currentPage);
        //每页记录数
        pageBean.setPageSize(pageSize);
        //数据
        int start = (currentPage - 1) * pageSize;
        List<WxFun> byPage = wxFunDao.findWxFunPage(start,pageSize);
        pageBean.setList(byPage);
        return pageBean;
    }

    @Override
    public WxFun findByFid(Integer fid) {
        WxFun wxFun = wxFunDao.findByFid(fid);
        if (wxFun == null){
            return null;
        }
        return wxFun;
    }

    public void delWxfun(Integer id){
        wxFunDao.delWxfun(id);
    }

    @Override
    public int updateWxFun(WxFun wxFun) {
        return wxFunDao.updateWxFun(wxFun);
    }

    @Override
    public int delWxfunByIds(List list) {
        return wxFunDao.delWxFunByIds(list);
    }


}
